home *** CD-ROM | disk | FTP | other *** search
/ 3D Games (Spidla) / 3dhry1.iso / mAz Lite 1.0 / messages.wdl < prev    next >
Encoding:
Text File  |  2003-03-17  |  7.4 KB  |  300 lines

  1. // Template file v5.202 (02/20/02)
  2. ////////////////////////////////////////////////////////////////////////
  3. // File: messages.wdl
  4. //        WDL prefabs for displaying messages
  5. ////////////////////////////////////////////////////////////////////////
  6.  
  7. ////////////////////////////////////////////////////////////////////////
  8. IFNDEF MSG_DEFS;
  9.  FONT standard_font,<ackfont.pcx>,6,9;
  10.  
  11.  DEFINE MSG_X,4;        // from left
  12.  DEFINE MSG_Y,4;        // from above
  13.  DEFINE BLINK_TICKS,6;    // msg blinking period
  14.  DEFINE MSG_TICKS,64;    // msg appearing time
  15.  DEFINE msg_font,standard_font;
  16.  SOUND msg_sound,<msg.wav>;
  17.  
  18.  DEFINE PANEL_POSX,4;    // health panel from left
  19.  DEFINE PANEL_POSY,-20;    // from below
  20.  FONT digit_font,<digfont.pcx>,12,16;    // ammo/health font
  21. ENDIF;
  22.  
  23. IFNDEF MSG_DEFS2;
  24.  DEFINE SCROLL_X,4;        // scroll text from left
  25.  DEFINE SCROLL_Y,4;        // from above
  26.  DEFINE SCROLL_LINES,4;    // maximum 8;
  27. ENDIF;
  28.  
  29. IFNDEF MSG_DEFS3;
  30.  DEFINE HEALTHPANEL,game_panel;    // default health/ammo panel
  31.  
  32.  DEFINE touch_font,standard_font;
  33.  DEFINE touch_sound,msg_sound;
  34. ENDIF;
  35.  
  36. //////////////////////////////////////////////////////////////////////
  37. var msg_counter = 0;
  38. STRING empty_str[80];
  39. STRING temp_str[80];
  40.  
  41. TEXT msg
  42. {
  43.     POS_X MSG_X;
  44.     POS_Y MSG_Y;
  45.     FONT    msg_font;
  46.     STRING empty_str;
  47. }
  48.  
  49. //////////////////////////////////////////////////////////////////////
  50. // To display a message string for a given number of seconds, perform the instructions
  51. // msg_show(string,time);
  52.  
  53. function msg_show(str,secs)
  54. {
  55.     exclusive_global;        // stop previous msg_show action
  56.     play_sound(msg_sound,66);
  57.     msg.string = str;
  58.     msg.visible = on;
  59.     waitt(secs*16);
  60.     msg.string = empty_str;
  61.     msg.visible = off;
  62. }
  63.  
  64. // Desc: show message for 5 seconds
  65. function show_message()
  66. {
  67.     msg_show(msg.string,5);
  68. }
  69.  
  70. // The same, but message will blink
  71. function msg_blink(str,secs)
  72. {
  73. //    ME = NULL;
  74.     exclusive_global;
  75.     play_sound(msg_sound,66);
  76.     msg.string = str;
  77.     msg_counter = secs*16;
  78.     while(msg_counter > 0)
  79.     {
  80.         msg.visible = (msg.visible == off);
  81.         waitt(BLINK_TICKS);
  82.         msg_counter -= BLINK_TICKS;
  83.     }
  84.     msg.string = empty_str;
  85.     msg.visible = off;
  86. }
  87.  
  88. function blink_message()
  89. {
  90.     msg_blink(msg.string,5);
  91. }
  92.  
  93. //////////////////////////////////////////////////////////////////////
  94. // actions for scrolling messages
  95. //////////////////////////////////////////////////////////////////////
  96. STRING message_str,
  97.  "                                                                    ";
  98. TEXT enter_txt
  99. {
  100.     FONT    msg_font;
  101.     STRING message_str;
  102. }
  103.  
  104. TEXT scroll
  105. {
  106.     POS_X MSG_X;
  107.     POS_Y MSG_Y;
  108.     FONT    msg_font;
  109.     STRINGS 8;
  110.     STRING "                                                           ";
  111.     STRING "                                                           ";
  112.     STRING "                                                           ";
  113.     STRING "                                                           ";
  114.     STRING "                                                           ";
  115.     STRING "                                                           ";
  116.     STRING "                                                           ";
  117.     STRING "                                                           ";
  118.     INDEX SCROLL_LINES;
  119. }
  120.  
  121. string* scroll_string;
  122.  
  123. // Desc: scroll message upwards while adding a line
  124. // Mod Date: 14/03/01 JCL - str parameter added
  125. function scroll_message(str)
  126. {
  127.     if (str) {
  128.         str_cpy(scroll.STRING[SCROLL_LINES],str);
  129.     }
  130.     play_sound(msg_sound,66);
  131.     scroll.VISIBLE = ON;
  132.     temp = 1;
  133.     while(temp <= SCROLL_LINES)
  134.     {
  135.     // scroll upwards by copying each string to the previous one
  136.         str_cpy(scroll.STRING[temp-1],scroll.STRING[temp]);
  137.         temp += 1;
  138.     }
  139.     // clear the last string
  140.     str_cpy(scroll.STRING[SCROLL_LINES],empty_str);
  141. }
  142.  
  143. string* message_syn = message_str;
  144.  
  145. // 14/03/01 JCL - display player name
  146. // prompt for a message and send it to the other players
  147. function enter_message()
  148. {
  149.     enter_txt.VISIBLE = ON;
  150.     enter_txt.POS_X = scroll.POS_X;
  151.     enter_txt.POS_Y = scroll.POS_Y + SCROLL_LINES * scroll.CHAR_Y;
  152.     str_cpy(message_str,player_name);
  153.     str_cat(message_str,": ");
  154.     inkey(message_str);
  155.     if(result == 13)
  156.     {
  157.          send_string(message_str);
  158.     }
  159.     enter_txt.VISIBLE = OFF;
  160. }
  161.  
  162. function server_event(str)
  163. {
  164.     if (event_type == event_join)
  165.     {
  166.         str_cpy(temp_str,str);
  167.         str_cat(temp_str," joined");
  168.         scroll_message(temp_str);
  169.         return;
  170.     }
  171.     if (event_type == event_leave)
  172.     {
  173.         str_cpy(temp_str,str);
  174.         str_cat(temp_str," left");
  175.         scroll_message(temp_str);
  176.         return;
  177.     }
  178.     if ((event_type == event_string) && (str == message_syn)) // pointers can be compared directly
  179.     {
  180. // server received message -> send it to all clients
  181.          send_string(message_syn);
  182.         return;
  183.     }
  184. }
  185.  
  186. // client received message -> display it
  187. function client_event(str)
  188. {
  189.     if ((event_type == event_string) && (str == message_syn))
  190.     {
  191.         scroll_message(message_syn);
  192.         str_cpy(message_syn,empty_str);
  193.         return;
  194.     }
  195. }
  196.  
  197. //////////////////////////////////////////////////////////////////////
  198. // actions for ammo and health panels
  199. //////////////////////////////////////////////////////////////////////
  200. var show_ammo = 0;
  201. var show_health = 0;
  202. var show_armor = 0;
  203. var ammo_number = 0;
  204. var ammo1 = 0;
  205. var ammo2 = 0;
  206. var ammo3 = 0;
  207. var ammo4 = 0;
  208. var ammo5 = 0;
  209. var ammo6 = 0;
  210. var ammo7 = 0;
  211.  
  212. PANEL game_panel
  213. {
  214.     POS_X        PANEL_POSX;
  215.     DIGITS    0,0,3,digit_font,1,show_ammo;
  216.     DIGITS    40,0,3,digit_font,1,show_health;
  217.     DIGITS    80,0,3,digit_font,1,show_armor;
  218.     FLAGS        TRANSPARENT,REFRESH;
  219. }
  220.  
  221. //////////////////////////////////////////////////////////////////////
  222.  
  223. // Desc: show player panel (ammo and heath)
  224. //
  225. // Mod:  05/01/01 DCP
  226. //        Added ammo5, ammo6, & ammo7
  227. function show_panels()
  228. {
  229.     HEALTHPANEL.VISIBLE = ON;
  230.     while(1)
  231.     {    // forever
  232.         HEALTHPANEL.POS_Y = SCREEN_SIZE.Y + PANEL_POSY;
  233.         if(ammo_number == 0) { show_ammo = 0; }
  234.         if(ammo_number == 1) { show_ammo = ammo1; }
  235.         if(ammo_number == 2) { show_ammo = ammo2; }
  236.         if(ammo_number == 3) { show_ammo = ammo3; }
  237.         if(ammo_number == 4) { show_ammo = ammo4; }
  238.         if(ammo_number == 5) { show_ammo = ammo5; }
  239.         if(ammo_number == 6) { show_ammo = ammo6; }
  240.         if(ammo_number == 7) { show_ammo = ammo7; }
  241.         if(player != NULL)
  242.         {
  243.             show_health = player._HEALTH;
  244.             show_armor = player._ARMOR;
  245.         }
  246.         wait(1);
  247.     }
  248. }
  249.  
  250. //////////////////////////////////////////////////////////////////////
  251. // Stuff for displaying object titles if the mouse touches them
  252. TEXT touch_txt
  253. {
  254.     FONT    touch_font;
  255.     STRING empty_str;
  256.     FLAGS CENTER_X,CENTER_Y;
  257. }
  258.  
  259. // Desc: display a touch text at mouse position
  260. function _show_touch()
  261. {
  262.     if(MY.STRING1 != NULL)
  263.     {
  264.         play_sound(touch_sound,33);
  265.         touch_txt.VISIBLE = ON;
  266.         touch_txt.STRING = MY.STRING1;
  267.         touch_txt.POS_X = MOUSE_POS.X;
  268.         touch_txt.POS_Y = MOUSE_POS.Y;
  269.         MY.ENABLE_RELEASE = ON;
  270.  
  271.     //    WHILE (touch_text.VISIBLE == ON)    // move text with mouse
  272.     //    {
  273.     //        touch_text.POSX = MOUSE_X;
  274.     //        touch_text.POSY = MOUSE_Y;
  275.     //        wait(1);
  276.     //    }
  277.     }
  278. }
  279.  
  280. // Desc: hide touch text if it still displayed my string
  281. function _hide_touch()
  282. {
  283.     if(touch_txt.STRING == MY.STRING1)
  284.     {
  285.         touch_txt.VISIBLE = OFF;
  286.     }
  287. }
  288.  
  289. // Desc: call this from a event action to operate the touch text
  290. function handle_touch()
  291. {
  292.     if(EVENT_TYPE == EVENT_TOUCH) { _show_touch(); return; }
  293.     if(EVENT_TYPE == EVENT_RELEASE) { _hide_touch(); return; }
  294. }
  295.  
  296. //////////////////////////////////////////////////////////////////////
  297. ON_SERVER = server_event;
  298. ON_CLIENT = client_event;
  299.  
  300. ON_F4 = enter_message;